﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using seo.Data;
using seo.dbutils;
using MySql.Data.MySqlClient;
using seo.DAO;

namespace seo.Buz
{
    class YiLookBuz
    {

        public List<YiLookChapter> GetChaptersByArt(int artid)
        {
            List<YiLookChapter> list = new List<YiLookChapter>();
            MySqlConnection conn = dbConnection.getLocalDbConnection();
            conn.Open();
            YiLookDao dao = new YiLookDao(conn);
            list = dao.GetChaptersByArt(artid);            
            return list;
        }

        public List<YiLookChapter> GetUnUploadChaptersByArt(int artid)
        {
            List<YiLookChapter> list = new List<YiLookChapter>();
            MySqlConnection conn = dbConnection.getLocalDbConnection();
            conn.Open();
            YiLookDao dao = new YiLookDao(conn);
            list = dao.GetUnUploadChaptersByArt(artid);
            return list;
        }

        public int InsertArt(string url)
        {
            int insertCount = 0;
            
            MySqlConnection conn = dbConnection.getLocalDbConnection();
            conn.Open();
            MySqlTransaction trans = conn.BeginTransaction();
            try
            {
                YiLookDao dao = new YiLookDao(conn);
                insertCount = dao.InsertArt(url);
                trans.Commit();
            }
            catch (Exception ex)
            {
                //trans.Rollback();   
                //throw ex;
            }
            finally
            {
                conn.Close();
            }

            return insertCount;
        }

        public int InsertChapter(YiLookChapter chapter)
        {
            int insertCount = 0;

            MySqlConnection conn = dbConnection.getLocalDbConnection();
            conn.Open();
            MySqlTransaction trans = conn.BeginTransaction();
            try
            {
                YiLookDao dao = new YiLookDao(conn);
                insertCount = dao.InsertChapter(chapter);
                trans.Commit();
            }
            catch (Exception ex)
            {
                //trans.Rollback();   
                //throw ex;
            }
            finally
            {
                conn.Close();
            }

            return insertCount;
        }
    }
}
